package createThread.sellTikcetDemo2;

/**
 * @author wang'ji'cheng
 * @date 2025/7/25
 */
public class SellTicket implements Runnable {

    static int num = 100;

    @Override
    public void run() {
        while (true) {
            synchronized (SellTicket.class) {
                if (num ==0) {
                    System.out.println("票卖完了");
                    return;
                } else {
                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    num--;
                    System.out.println(Thread.currentThread().getName() + "在卖票,还有" + num);

                }

            }
        }
    }
}
